<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Edit Customer | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        
        <f:view beforePhase="#{editCustomerManagerBean.initView}">
            
            <p:panel id="panel" header="Edit Sale Lead"> 
            
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus> 

            <p:messages /> 
            <h:form id="form1" prependId="false">
                <p:fieldset legend="Company Details" style="font-weight: bold">
                <h:panelGrid columns="3" cellpadding="10"> 
                    <h:outputLabel for="saleLeadName" style="font-weight: bold" value="Company Name: " /> 
                    <p:inputText value="#{editCustomerManagerBean.customerToEdit.saleLeadName}" required="true" label="Sale Lead Name" requiredMessage="Sale Lead Name is required." id="saleLeadName">                      
                    </p:inputText> 
                    <p:message for="saleLeadName" /> 
                    
                    <h:outputLabel for="registrationNumber" style="font-weight: bold" value="Registration Number: " /> 
                    <h:outputText value="#{editCustomerManagerBean.customerToEdit.registrationNumber}" id="registrationNumber" />
                    <p:message for="registrationNumber" />  
                    
                    <h:outputLabel for="address" style="font-weight: bold" value="Address: " /> 
                    <p:inputText required="true" label="address" requiredMessage="Address is required." id="address" value="#{editCustomerManagerBean.customerToEdit.saleLeadAddress}"> 
                        
                    </p:inputText> 
                    <p:message for="address" /> 
                    <h:outputLabel for="customerType" style="font-weight: bold" value="Customer Type: " /> 
                    <h:selectOneMenu id ="customerType" value="#{editCustomerManagerBean.customerToEdit.customerType}">
                        <f:selectItem itemValue="WholeSale" itemLabel="Whole Sale" id="wholeSale" />
                        <f:selectItem itemValue="DirectSale" itemLabel="Direct Sale" id="directSale" />
                    </h:selectOneMenu>
                    
                    <p:message for="customerType" />
                    
                </h:panelGrid>     
                </p:fieldset>
                <br/>
                <p:fieldset legend="Representative Details">
                    <p:commandButton value="Add New" onclick="addRepDialog.show()" ajax="true"/>
                    <p:commandButton value="Edit" update="display1" oncomplete="editRepDialog.show()" />
                    <p:commandButton value="Delete" update="display1" oncomplete="deleteRepDialog.show()" />
                    <p:separator />
                    <p:dataTable value="#{editCustomerManagerBean.reps}" var="rep" id="repTable" selection="#{editCustomerManagerBean.selectedRep}">
                        <p:column selectionMode="single" />
                        <p:column sortBy="#{rep.name}" style="width: 30%">     
                            <f:facet name="header"> 
                                <h:outputText value="Representative Name" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.name}" /> 
                        </p:column>

                        <p:column sortBy="#{rep.email}" style="width: 40%"> 
                            <f:facet name="header"> 
                                <h:outputText value="Email" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.email}" /> 
                        </p:column>

                        <p:column sortBy="#{rep.contactNumber}" style="width: 30%"> 
                            <f:facet name="header"> 
                                <h:outputText value="Contact Number" /> 
                            </f:facet> 
                            <h:outputText value="#{rep.contactNumber}" /> 
                        </p:column>
                    </p:dataTable>
                </p:fieldset>
                <br/>

                
                <p:commandButton id="btn" value="Update Sale Lead" update="panel" actionListener="#{editCustomerManagerBean.updateExistingCustomer}" ajax="true" />
            
                <p:confirmDialog message="Do you want to delete this representative?" widgetVar="deleteRepDialog">
                    <p:commandButton value="Yes" actionListener="#{editCustomerManagerBean.deleteRep}" oncomplete="deleteRepDialog.hide()"/>
                    <p:commandButton value="No" onclick="deleteRepDialog.hide()"/>
                </p:confirmDialog>
            </h:form>
            
             <h:form prependId="false">      
                <p:dialog header="Representative Detail" widgetVar="addRepDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display" columns="2">
                        <h:outputText value="Representative Name:"/>
                        <p:inputText value="#{editCustomerManagerBean.newRep.name}" required="true" requiredMessage="Representative Name is required"/>
                        <h:outputText value="Representative Email:"/>
                        <p:inputText value="#{editCustomerManagerBean.newRep.email}" required="true" requiredMessage="Representative Email is required"/>
                        <h:outputText value="Representative Contact Number: "/>
                        <p:inputText value="#{editCustomerManagerBean.newRep.contactNumber}" required="true" requiredMessage="Representative Contact Number is required"/>
                        <p:commandButton value="Add" actionListener="#{editCustomerManagerBean.addRep}" update="repTable display" oncomplete="addRepDialog.hide()"/>  
                    </h:panelGrid>
                </p:dialog>
             </h:form>
             <h:form prependId="false">
                 
                 <p:dialog header="Edit Representative" widgetVar="editRepDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2">
                        <h:outputText value="Representative Name:"/>
                        <p:inputText value="#{editCustomerManagerBean.selectedRep.name}" required="true" requiredMessage="Representative Name is required"/>
                        <h:outputText value="Representative Email:"/>
                        <h:outputText value="#{editCustomerManagerBean.selectedRep.email}"/>
                        <h:outputText value="Representative Contact Number: "/>
                        <p:inputText value="#{editCustomerManagerBean.selectedRep.contactNumber}" required="true" requiredMessage="Representative Contact Number is required"/>
                        <p:commandButton value="Edit" actionListener="#{editCustomerManagerBean.editRep}" update="repTable display1" oncomplete="editRepDialog.hide()"/>  
                    </h:panelGrid>
                </p:dialog>
            </h:form>
        </p:panel> 

        </f:view>
    </ui:define>

</ui:composition>
